/***************************************************************************************
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: figure_A8_alt_transfer_costs.do
Date: October 2022

Description: Reproduces Figure A.8: Country effects: Alternative specification of the technology transfer costs.

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
log using "${clogs}/figure_A8_alt_transfer_costs.log",replace
*-------------------------------------------------------------------------------


*Assuming the technology transfer costs have an origin-specific component
*-----------------------------------------------------------------
clear all
use year isocode type D_A* using "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear


*Assuming the technology transfer costs have an detination-specific component
*-----------------------------------------------------------------
merge 1:1 year isocode type using "${data}/estimates_agg_naics_sales_s1_base_withparent.dta", keepusing(D_P*)
drop if _merge==2
drop _merge


foreach xx in D_A D_P {
gen u_`xx' = `xx' + 1.96 * `xx'_se
gen l_`xx' = `xx' - 1.96 * `xx'_se 
}
keep year isocode type *D_A* *D_P*
gsort D_A
drop year

gen t=_n
sum t

forvalues ii=1(1)`r(max)' {
local ctry`ii' = isocode[`ii']
local obs`ii' = `ii'
display "`ctry`ii'' ; `obs`ii''"
}
*

twoway rcap u_D_A l_D_A t, lc(red) /// 
||     rcap u_D_P l_D_P t, lc(blue) /// 
||     scatter D_A t, mc(red)  /// 
||     scatter D_P t, mc(blue)  ///
yline(0) yline(0) ylab(-2(1)4) xlab(1(1)25)  legend(off) xlabel(, valuelabel) xlabel(, angle(45)) ytitle("") xtitle("") graphregion(fcolor(white) lcolor(white)) xlabel(`obs1' "`ctry1'" `obs2' "`ctry2'"  `obs3' "`ctry3'" `obs4' "`ctry4'" `obs5' "`ctry5'" `obs6' "`ctry6'" `obs7' "`ctry7'" `obs8' "`ctry8'" `obs9' "`ctry9'" `obs10' "`ctry10'" `obs11' "`ctry11'" `obs12' "`ctry12'" `obs13' "`ctry13'" `obs14' "`ctry14'" `obs15' "`ctry15'" `obs16' "`ctry16'" `obs17' "`ctry17'" `obs18' "`ctry18'" `obs19' "`ctry19'" `obs20' "`ctry20'"  `obs21' "`ctry21'" `obs22' "`ctry22'" `obs23' "`ctry23'" `obs24' "`ctry24'" `obs25' "`ctry25'" `obs26' "`ctry26'" `obs27' "`ctry27'", labsize(small)) 

graph export "${rappendix}/fig_A8_alt_transfer_costs.pdf", replace

	
log close 
	
	
	